﻿using System.ComponentModel.Composition;
using System.Windows;
using System.Windows.Controls;
using GiveAQuiz.QuizManager.Views;

namespace GiveAQuiz.QuizManager
{
  public partial class QuizEditor : UserControl
  {
    public QuizEditor()
    {
      InitializeComponent();

      Loaded += new RoutedEventHandler(QuizEditor_Loaded);
    }

    void ShowInfoView()
    {
      var view = new QuizInfoView();
      view.DataContext = ViewModel;
      view.Show();
    }

    void QuizEditor_Loaded(object sender, RoutedEventArgs e)
    {
      // Set the ViewModel to our data context directly
      // We are using resolution so the dependency chain is set up for us
      DataContext = ViewModel;
      
      // Show the information editor dialog
      // NOTE: Due to a limitation in the Messenger class, parameter is ignored
      AppMessages.EditDetailsMessage.Register(this, b => ShowInfoView());

      // If the test is new, show the info view first
      if (App.CurrentApp.IsNewQuiz)
      {
        ShowInfoView();
      }
    }

    [Import("QuizViewModel")]
    public object ViewModel
    {
      get;
      set;
    }

  }
}
